﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace demo
{
    public partial class ViewDetailsForm : BaseForm
    {
        protected int m_IdPosition;
        public int IdPosition
        {
            set { m_IdPosition = value; }
        }

        public ViewDetailsForm()
        {
            HideShowStatusMenu();
            InitializeComponent();
        }
        void ViewDetailsForm_Load(object sender, System.EventArgs e)
        {
            LoadData();
        }

        protected void LoadData()
        {
            demoDataSetTableAdapters.tb_PositionsTableAdapter PositionTableAdapter = null;
            demo.demoDataSet.tb_PositionsDataTable dt = null;
            demo.demoDataSet.tb_PositionsRow dr = null;
            try
            {
                PositionTableAdapter = new demo.demoDataSetTableAdapters.tb_PositionsTableAdapter();
                dt = new demoDataSet.tb_PositionsDataTable();
                PositionTableAdapter.FillByPosition(dt, m_IdPosition);
                dr = dt[0];

                labeldAngle.Text = dr.Angle.ToString();
                labeldGPSTime.Text = dr.Time.ToString();
                labeldLatitude.Text = dr.Latitude.ToString();
                labeldLongitude.Text = dr.Longitude.ToString();
                labeldAltitude.Text = dr.Altitude.ToString();
                labeldSatellite.Text = dr.Satellites.ToString();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                dr.Delete();
                dt.Clear();
                PositionTableAdapter.Dispose();

            }
        }

        public string ConvertDecimaltoDegreeLongitude(string Position)
        {
            string DegreeFormated = "0";
            if (Position != "0")
            {
                string[] arrPosition = Position.Split('.');
                double previewMinutes = double.Parse(arrPosition[0].Substring(3, 2));
                double previewDegree = double.Parse(arrPosition[0].Substring(0, 3));

                double previewSeconds = (double.Parse(arrPosition[1]) / 10000000) * 60;
                DegreeFormated = previewDegree.ToString() + " ° " + previewMinutes.ToString() + " ' " + previewSeconds.ToString() + " \" ";
                // 34º 36' 34.79'' = 34 + ( 36 / 60 ) + ( 34,79 / 3600 ) =  (expresado en decimal)
            }
            return DegreeFormated;


        }
        public string ConvertDecimaltoDegreeLatitude(string Position)
        {

            string DegreeFormated = "0";
            if (Position != "0")
            {
                string[] arrPosition = Position.Split('.');
                double previewMinutes = double.Parse(arrPosition[0].Substring(2, 2));
                double previewDegree = double.Parse(arrPosition[0].Substring(0, 2));
                double previewSeconds = (double.Parse(arrPosition[1]) / 10000000) * 60;
                DegreeFormated = previewDegree.ToString() + " ° " + previewMinutes.ToString() + " ' " + previewSeconds.ToString() + " \" ";
                // 34º 36' 34.79'' = 34 + ( 36 / 60 ) + ( 34,79 / 3600 ) =  (expresado en decimal)
            }
            return DegreeFormated;


        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            m_GPS.HasSolutionChanged -= new EventHandler(m_GPS_HasSolutionChanged);
            this.Close();
        }
        void buttonClose_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            this.Close();
        }



    }
}